home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / Book Chapters / Appendix A - Top Speed / Overhead / Overhead.c < prev    next >
C/C++ Source or Header  |  1995-03-08  |  3KB  |  117 lines

  1. #include <stdio.h>
  2.  
  3.  
  4. #define kLoopNumber 30000
  5. #define SetPtMacro(p,hh,vv)    p.h=hh;p.v=vv
  6.  
  7.  
  8. /* Standard inits */
  9.  
  10. static void InitToolbox(void) {
  11.     InitGraf (&qd.thePort);
  12.     InitFonts ();
  13.     FlushEvents (everyEvent,0);
  14.     InitWindows ();
  15.     InitMenus ();
  16.     TEInit ();
  17.     InitDialogs (nil);
  18.     InitCursor ();
  19. } /*InitToolbox*/
  20.  
  21.  
  22. void MySetPt(Point *thePoint, short h, short v)
  23. {
  24.     thePoint->h = h;
  25.     thePoint->v = v;
  26. } /*MySetPt*/
  27.  
  28.  
  29. typedef pascal void (*SetPtPtr)(Point *, short, short);
  30.  
  31.  
  32. void main(void)
  33. {
  34.     long    timeBefore,timeAfter;
  35.     short    loop;
  36.     Point    myPoint;
  37.     
  38.     SetPtPtr    setPtAddress;
  39.     
  40.     InitToolbox();
  41.     
  42.     timeBefore = TickCount();
  43.     for (loop = 0; loop < kLoopNumber; loop++)
  44.     {
  45.         SetPt(&myPoint, loop, loop);
  46.         SetPt(&myPoint, loop, loop);
  47.         SetPt(&myPoint, loop, loop);
  48.         SetPt(&myPoint, loop, loop);
  49.         SetPt(&myPoint, loop, loop);
  50.         SetPt(&myPoint, loop, loop);
  51.         SetPt(&myPoint, loop, loop);
  52.         SetPt(&myPoint, loop, loop);
  53.         SetPt(&myPoint, loop, loop);
  54.         SetPt(&myPoint, loop, loop);
  55.     }
  56.     timeAfter = TickCount();
  57.     printf("Trap call: %ld ticks for %ld calls.\n", timeAfter-timeBefore, (long)kLoopNumber*10);
  58.  
  59.  
  60.     setPtAddress = (SetPtPtr) NGetTrapAddress(_SetPt,ToolTrap);
  61. //  _SetPt = $A880;
  62.     timeBefore = TickCount();
  63.     for (loop = 0; loop < kLoopNumber; loop++)
  64.     {
  65.         (*setPtAddress)(&myPoint, loop, loop);
  66.         (*setPtAddress)(&myPoint, loop, loop);
  67.         (*setPtAddress)(&myPoint, loop, loop);
  68.         (*setPtAddress)(&myPoint, loop, loop);
  69.         (*setPtAddress)(&myPoint, loop, loop);
  70.         (*setPtAddress)(&myPoint, loop, loop);
  71.         (*setPtAddress)(&myPoint, loop, loop);
  72.         (*setPtAddress)(&myPoint, loop, loop);
  73.         (*setPtAddress)(&myPoint, loop, loop);
  74.         (*setPtAddress)(&myPoint, loop, loop);
  75.     }
  76.     timeAfter = TickCount();
  77.     printf("Trap direct: %ld ticks for %ld calls.\n", timeAfter-timeBefore, (long)kLoopNumber*10);
  78.  
  79.  
  80.     timeBefore = TickCount();
  81.     for (loop = 0; loop < kLoopNumber; loop++)
  82.     {
  83.         MySetPt(&myPoint, loop, loop);
  84.         MySetPt(&myPoint, loop, loop);
  85.         MySetPt(&myPoint, loop, loop);
  86.         MySetPt(&myPoint, loop, loop);
  87.         MySetPt(&myPoint, loop, loop);
  88.         MySetPt(&myPoint, loop, loop);
  89.         MySetPt(&myPoint, loop, loop);
  90.         MySetPt(&myPoint, loop, loop);
  91.         MySetPt(&myPoint, loop, loop);
  92.         MySetPt(&myPoint, loop, loop);
  93.     }
  94.     timeAfter = TickCount();
  95.     printf("Function call: %ld ticks for %ld calls.\n", timeAfter-timeBefore, (long)kLoopNumber*10);
  96.  
  97.  
  98.     timeBefore = TickCount();
  99.     for (loop = 0; loop < kLoopNumber; loop++)
  100.     {
  101.         SetPtMacro(myPoint, loop, loop);
  102.         SetPtMacro(myPoint, loop, loop);
  103.         SetPtMacro(myPoint, loop, loop);
  104.         SetPtMacro(myPoint, loop, loop);
  105.         SetPtMacro(myPoint, loop, loop);
  106.         SetPtMacro(myPoint, loop, loop);
  107.         SetPtMacro(myPoint, loop, loop);
  108.         SetPtMacro(myPoint, loop, loop);
  109.         SetPtMacro(myPoint, loop, loop);
  110.         SetPtMacro(myPoint, loop, loop);
  111.     }
  112.     timeAfter = TickCount();
  113.     printf("Macro: %ld ticks for %ld calls.\n", timeAfter-timeBefore, (long)kLoopNumber*10);
  114.  
  115.  
  116. } /*main*/
  117.